/*
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-11-04 09:49:56
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2023-08-16 17:14:21
 * @FilePath: \backstage - 副本\src\utils\config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export const sexType = {
    1: {
        label: '男',
        value: 1
    },
    2: {
        label: '女',
        value: 2
    },
    3: {
        label: '未知',
        value: 3
    }
}
export const objectType = {
    0: {
        label: '否',
        value: 0
    },
    1: {
        label: '是',
        value: 1
    }
}
export const messageType = {
    1: {
        label: '短信',
        value: 1
    },
    2: {
        label: '微信公众号',
        value: 2
    },
    3: {
        label: '短信和微信公众号',
        value: 3
    }
}
export const roleType = {
    1: {
        label: '一号选手',
        value: 1,
        className: 'color1'
    },
    2: {
        label: '二号选手',
        value: 2,
        className: 'color2'
    },
    3: {
        label: '三号选手',
        value: 3,
        className: 'color3'
    }
}
export const statusType = {
    0: {
        label: '正常',
        value: "0",
        className: 'success'
    },
    1: {
        label: '初级',
        value: "1",
        className: 'plain'
    },
    2: {
        label: '中级',
        value: "2",
        className: 'warning'
    },
    3: {
        label: '高级',
        value: "3",
        className: 'danger'
    }
}
export const statusTypes = {
    0: {
        label: '正常',
        value: "0",
        className: 'success'
    },
    1: {
        label: '初级',
        value: "1",
        className: 'plain'
    },
    2: {
        label: '中级',
        value: "2",
        className: 'warning'
    },
    3: {
        label: '高级',
        value: "3",
        className: 'danger'
    }
}
export const statusTypes1 = {
    0: {
        label: '合格',
        value: "0",
        className: 'success'
    },
    1: {
        label: '不合格',
        value: "1",
        className: 'danger'
    },
   
}
export const statusType2 = {
    // 砼拌合站等级
    0: {
        label: '正常',
        value: "0",
        className: 'success',
      
    },
    1: {
        label: '一级',
        value: "1",
        className: 'plain',
    },
    2: {
        label: '二级',
        value: "2",
        className: 'warning',

    },
    3: {
        label: '三级',
        value: "3",
        className: 'danger',
    },
    4: {
        label: '四级',
        value: "4",
        className: 'purple',
    
    },
    5: {
        label: '五级',
        value: "5",
        className: 'brown',
       
    }
}
// export const statusType3 = {
//     // 砼拌合站等级
//     0: {
//         label: '已完成',
//         value: "已完成",
//         className: 'success',
      
//     },
//     1: {
//         label: '未提交',
//         value: "未提交",
//         className: 'danger',
//     },
//     2: {
//         label: '未完成',
//         value: "未完成",
//         className: 'warning',

//     },
   
// }
// 
export const type = {
    0: {
        label: '拌合站',
        value: 0,
        className: 'success'
    },
    1: {
        label: '拌合机',
        value: 1,
        className: 'plain'
    },
    2: {
        label: '拌合机',
        value: 1,
        className: 'plain'
    },
    3: {
        label: '拌合机',
        value: 1,
        className: 'plain'
    },
    4: {
        label: '拌合机',
        value: 1,
        className: 'plain'
    },
}
export const types = {
    0: {
        label: '梁场',
        value: 0,
        className: 'success'
    },
    4: {
        label: '张拉机',
        value: 1,
        className: 'plain'
    },
    5: {
        label: '压浆机',
        value: 1,
        className: 'plain'
    },
}
import {
    getUserCompanyTreeList,

} from "@/api/request.js";
var userInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_userInfo"));
var treeDatas = []
var treelengths = null
var names = null

export const treeData = () => {
    var treeText = {
        companyId: userInfo.companyId,
        userId: userInfo.userId
    }

    getUserCompanyTreeList(treeText)
        .then((res) => {
            if (res.errcode == 0) {
                var companyTree = res.data.userCompanyTreeList;
                treeDatas = tranListToTreeData(companyTree);

                if (treeDatas[0].children == undefined) {
                    treelengths = false;
                } else {
                    treelengths = true;
                }
                names = treeDatas[0].fShortname;
                return {
                    treeDatas: treeDatas,
                    treelengths: treelengths,
                    names: names
                }
            } else {
                this.$message.error(res.msg);

                return false;
            }
        })
        .catch(() => {
            return false;
        });
    // return up("post", url + "App/upload/uploadFile.do", res)
}


function tranListToTreeData(data) {
    let result = [];
    if (!Array.isArray(data)) {
        return result;
    }
    // 清除已存在的children 重新赋值
    data.forEach((item) => {
        delete item.children;
    });

    let map = {};
    data.forEach((item) => {
        map[item.fCompanyid] = item;
    });

    data.forEach((item) => {
        let parent = map[item.fParentid];
        if (parent) {
            (parent.children || (parent.children = [])).push(item);
        } else {
            result.push(item);
        }
    });
    return result;
}